/*     */ package com.zimbra.cs.account.callback;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.AttributeCallback;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class TrustedSenderList
/*     */   extends AttributeCallback
/*     */ {
/*     */   public void preModify(CallbackContext context, String name, Object value, Map mod, Entry entry)
/*     */     throws ServiceException
/*     */   {
/*  63 */     if ((context.isCreate()) || (!(entry instanceof Account))) {
/*  64 */       return;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*  69 */     if (context.isDoneAndSetIfNot(TrustedSenderList.class)) {
/*  70 */       return;
/*     */     }
/*     */     
/*  73 */     Account account = (Account)entry;
/*     */     
/*  75 */     int max = account.getMailTrustedSenderListMaxNumEntries();
/*     */     
/*  77 */     Object replace = mod.get(name);
/*  78 */     Object add = mod.get("+" + name);
/*  79 */     Object remove = mod.get("-" + name);
/*     */     
/*  81 */     if (replace != null) {
/*  82 */       Set<String> set = getMultiValueSet(replace);
/*  83 */       if (set.size() > max) {
/*  84 */         throw AccountServiceException.TOO_MANY_TRUSTED_SENDERS(set.size() + " > " + max);
/*     */       }
/*     */     }
/*     */     else {
/*  88 */       String[] current = account.getMultiAttr(name, false);
/*     */       
/*  90 */       if (add != null) {
/*  91 */         Set<String> set = getMultiValueSet(add);
/*  92 */         if (current.length > 0) {
/*  93 */           if (current.length + set.size() > max) {
/*  94 */             throw AccountServiceException.TOO_MANY_TRUSTED_SENDERS(current.length + " + " + set.size() + " > " + max);
/*     */           }
/*     */         }
/*     */         else {
/*  98 */           List<String> def = getMultiValue(account.getAttrDefault(name));
/*  99 */           if (def.size() + set.size() > max) {
/* 100 */             throw AccountServiceException.TOO_MANY_TRUSTED_SENDERS(def.size() + " + " + set.size() + " > " + max);
/*     */           }
/*     */           
/* 103 */           set.addAll(def);
/* 104 */           mod.put("+" + name, set);
/*     */         }
/*     */       }
/*     */       
/* 108 */       if ((remove != null) && 
/* 109 */         (current.length == 0)) { Set<String> def;
/*     */         Set<String> def;
/* 111 */         if (add == null) {
/* 112 */           def = getMultiValueSet(account.getAttrDefault(name));
/*     */         } else {
/* 114 */           def = (Set)mod.get("+" + name);
/* 115 */           assert (def != null);
/*     */         }
/* 117 */         def.removeAll(getMultiValueSet(remove));
/* 118 */         mod.remove("-" + name);
/* 119 */         mod.put("+" + name, def);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void postModify(CallbackContext context, String attrName, Entry entry) {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/TrustedSenderList.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */